public class PowerOfThree {
    public static boolean isPowerOfThree(int n) {
        boolean flag = true;
        while(n>1){
            int temp = n%3;
            n = n/3;
            if(temp!=0){
                flag = false;
                break;
            }
        }

        return flag;
    }

    public static void main(String[] args) {
        isPowerOfThree(27);
    }
}
